import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // title是打开任务管理器的时候显示的title
    return MaterialApp(title: 'material App', routes: {"/otherPage": (BuildContext context) => OtherPage()}, home: HomePage());
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var _currentIndex = 0;

  final _widgetOption = [Text("信息"), Text("邮箱"), Text("个人")];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: buildDrawer(),
      appBar: buildAppBar(),
      body: _widgetOption.elementAt(_currentIndex),
      floatingActionButton: buildFloatingActionButton(context),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.message), title: Text("message")),
          BottomNavigationBarItem(icon: Icon(Icons.mail), title: Text("mail")),
          BottomNavigationBarItem(icon: Icon(Icons.person), title: Text("person")),
        ],
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed, // 防止底部导航栏看不见
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }

  FloatingActionButton buildFloatingActionButton(BuildContext context) {
    return FloatingActionButton(
      onPressed: () {
        Navigator.pushNamed(context, "/otherPage");
      },
      child: Icon(Icons.arrow_right),
      tooltip: '跳转',
      foregroundColor: Color(0xffffffff),
      backgroundColor: Color(0xff000000),
      elevation: 3,
      shape: RoundedRectangleBorder(),
    );
  }

  AppBar buildAppBar() {
    return AppBar(
      title: Text("material app"),
      leading: Icon(Icons.favorite),
      actions: <Widget>[
        SizedBox(
          width: 20,
        ),
        Icon(
          Icons.star,
        ),
        SizedBox(
          width: 20,
        ),
        Icon(Icons.save),
      ],
      centerTitle: true,
    );
  }

  Drawer buildDrawer() {
    return Drawer(
      child: ListView(
        children: <Widget>[
          UserAccountsDrawerHeader(
            currentAccountPicture: CircleAvatar(
              backgroundImage:
                  NetworkImage('http://att3.citysbs.com/200x200/hangzhou/2020/04/15/11/dd6719bd4287d9efd49434c43563a032_v2_.jpg'),
            ),
            accountName: Text("user"),
            accountEmail: Text('790710584@qq.com'),
            otherAccountsPictures: <Widget>[
              Icon(Icons.camera),
            ],
            decoration: BoxDecoration(image: DecorationImage(image: AssetImage('assets/images/img1.jpg'), fit: BoxFit.fill)),
          ),
          ListTile(
            leading: Icon(Icons.star),
            title: Text("开会员"),
          ),
          ListTile(
            leading: Icon(Icons.star),
            title: Text("开会员"),
          ),
          ListTile(
            leading: Icon(Icons.star),
            title: Text("开会员"),
          ),
          AboutListTile(
            icon: Icon(Icons.favorite),
            child: Text("关于"),
            applicationIcon: Icon(Icons.person),
            applicationName: "aaa",
            applicationVersion: "1.1",
            applicationLegalese: "aa",
          )
        ],
      ),
    );
  }
}

class OtherPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("ohther page"),
      ),
    );
  }
}
